﻿using BulkUploadGovernanceFiles.Models;
using BulkUploadGovernanceFiles.MongoSpecification;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;

namespace BulkUploadGovernanceFiles.Repositories
{
    public class GovernanceInsightInputFileRepository
    {
        private readonly MongoCollection<GovernanceInsightInputFile> _governanceInsightCollection;

        public GovernanceInsightInputFileRepository()
        {
            var mongoClient = new MongoClient(ConfigManager.GovernanceInputFile.ConnectionString);
            var server = mongoClient.GetServer();
            var database = server.GetDatabase(ConfigManager.GovernanceInputFile.DataBaseName);

            _governanceInsightCollection = database.GetCollection<GovernanceInsightInputFile>("GovernanceInsightInputFile");
        }

        public GovernanceInsightInputFile GetByCompanyId(ISpecification<GovernanceInsightInputFile> specification)
        {
            return _governanceInsightCollection.AsQueryable<GovernanceInsightInputFile>().FirstOrDefault(specification.SpecExpression);
        }

        public void InsertNew(GovernanceInsightInputFile insightInpuFile)
        {
            _governanceInsightCollection.Insert(insightInpuFile);
        }

        public void DeleteExisting()
        {
            _governanceInsightCollection.RemoveAll();
        }
    }
}
